// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SourceFile

package com.sgame.android.network;

import android.content.Context;
import com.sgame.android.MLog;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.zip.GZIPInputStream;
import org.apache.http.*;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.conn.scheme.*;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.*;
import org.apache.http.protocol.*;

// Referenced classes of package com.mobage.ww.android.network:
//            HttpRequest, a, k, b

public class ExecuteHttpRequest
{
    private static class GzipHttpEntity extends HttpEntityWrapper
    {

        public final InputStream getContent()
            throws IOException
        {
            return new GZIPInputStream(wrappedEntity.getContent());
        }

        public final long getContentLength()
        {
            return -1L;
        }

        public GzipHttpEntity(HttpEntity httpentity)
        {
            super(httpentity);
        }
    }


    public ExecuteHttpRequest()
    {
        mUrl = "";
        e = 5;
        f = 10;
        g = 10000;
        BasicHttpParams basichttpparams;
        ConnManagerParams.setTimeout(basichttpparams = new BasicHttpParams(), g);
        ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(f));
        ConnManagerParams.setMaxTotalConnections(basichttpparams, 10);
        HttpConnectionParams.setSoTimeout(basichttpparams, g);
        HttpConnectionParams.setConnectionTimeout(basichttpparams, g);
        HttpConnectionParams.setTcpNoDelay(basichttpparams, true);
        HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192);
        HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setUserAgent(basichttpparams, String.format("android-async-http/%s (http://loopj.com/android-async-http)", new Object[] {
            "1.3.1"
        }));
        Object obj;
        ((SchemeRegistry) (obj = new SchemeRegistry())).register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        ((SchemeRegistry) (obj)).register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
        obj = new ThreadSafeClientConnManager(basichttpparams, ((SchemeRegistry) (obj)));
        mDefaultHttpClient = new DefaultHttpClient(((org.apache.http.conn.ClientConnectionManager) (obj)), basichttpparams);
        mDefaultHttpClient.addResponseInterceptor(new HttpResponseInterceptor() {

            public final void process(HttpResponse response, HttpContext httpcontext)
            {
                Header header = response.getEntity().getContentEncoding();
                HttpResponse httpresponse = response;
                String s = new String();
                Header aheader[];
                int j1 = (aheader = httpresponse.getAllHeaders()).length;
                for(int k1 = 0; k1 < j1; k1++)
                {
                    header = aheader[k1];
                    s = (new StringBuilder()).append(s).append(header.getName()).append(":").append(header.getValue()).toString();
                }

                if(header != null)
                {
                	HeaderElement [] elements = header.getElements();
                    int l = elements.length;
                    for(int i1 = 0; i1 < l; i1++)
                        if(elements[i1].getName().equalsIgnoreCase("gzip"))
                        {
                            response.setEntity(new GzipHttpEntity(response.getEntity()));
                            return;
                        }

                }
            }
        }
        );
        mDefaultHttpClient.setHttpRequestRetryHandler(new HttpRequestRetry(e));
        mThreadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool();
    }

    public final void setCookieStore(CookieStore cookiestore) //a
    {
        mHttpContext.setAttribute("http.cookie-store", cookiestore);
    }

    public final void setThreadPool(ThreadPoolExecutor threadpoolexecutor) //a
    {
        mThreadPool = threadpoolexecutor;
    }

    public final void setUrl(String s) //a
    {
    	mUrl = s;
    }

    public final String getUrl() //a
    {
        return mUrl;
    }

    public final void setUserAgent(String s) //b
    {
        HttpProtocolParams.setUserAgent(mDefaultHttpClient.getParams(), s);
    }

    void InitHeader(HttpUriRequest httpurirequest) //a
    {
        httpurirequest.addHeader("Accept", "application/json");
        httpurirequest.addHeader("Accept-Encoding", "gzip");
    }

    public void Execute(HttpRequest httprequest, AsyncHttpResponseHandler b1) //a
    {
        HttpUriRequest httpurirequest = httprequest.getUriRequest(mUrl);
        LinkedList list;
        InitHeader(httpurirequest);
        Future<?> future = mThreadPool.submit(new AsyncHttpRequest(mDefaultHttpClient, mHttpContext, httpurirequest, b1, httprequest));
        if(mContext != null)
        {
        	list = (LinkedList)mMap.get(mContext);
            if(list == null)
            {
            	list = new LinkedList();
                mMap.put(mContext, list);
            }
            list.add(new WeakReference(httprequest));
        }
    }

    private final String mDataType = "application/json";
    private final boolean b = false;
    private String mUrl;
    private Context mContext;
    private int e;
    private int f;
    private int g;
    private final DefaultHttpClient mDefaultHttpClient;
    private final HttpContext mHttpContext = new SyncBasicHttpContext(new BasicHttpContext());
    private ThreadPoolExecutor mThreadPool;
    private final Map mMap = new WeakHashMap();
}
